home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / DELPHI.SWG / 0020_Close a file opened from a Delphi DLL in.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  1.3 KB  |  37 lines

  1. {
  2. Q:  How do I close a file that was opened in a DLL (Delphi
  3. made) and called from VB?
  4.  
  5. A:  This is a known problem. It comes from the fact that VB
  6. closes the 5 DOS standard handles (0..4) at startup. So the
  7. open file routine will reuse one of these handles to open the
  8. first disk file. That is not a problem in using the file, but
  9. the Pascal Close routine has a build-in safety feature: it
  10. refuses to close a file that has one of the standard handles!
  11. That is a Good Thing under DOS but screws up the works in your
  12. situation since the file opened by the DLL is never closed, not
  13. even when the DLL goes down! VC++ is obviously less restricted
  14. and will close a standard handle.
  15.  
  16. You can fix this problem yourself.  Instead of using the Pascal
  17. Close/CloseFile routine to close the file in the DLL, use one
  18. of these:
  19. }
  20.  
  21. Procedure ReallyCloseFileVar(Var F); Assembler;
  22. { F should be a file type }
  23. Asm
  24.   les  bx, F                { store F in es:bx }
  25.   mov  bx, word ptr es:[bx] { store handle in bx }
  26.   mov  ah, $3E              { function 3Eh = close file }
  27.   call Dos3Call             { execute int 21h }
  28. End;
  29.  
  30. Procedure ReallyCloseFileHandle(FileHandle: word); assembler;
  31. { FileHandle is the DOS file handle }
  32. asm
  33.   mov  bx, Handle { store handle in bx }
  34.   mov  ah, $3E    { function 3Eh = close file }
  35.   call DOS3Call   { execute int 21h }
  36. end;
  37.